<%-- 
    Document   : messages
    Created on : Mar 4, 2014, 10:36:09 PM
    Author     : Jordan
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<c:set scope="request" var="title" value="Contract"/>

<sql:setDataSource user="root" password="" driver="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost/bonix"/>


<sql:query var="getConversation">
    select sender,receiver,msg,sent_date from messages where receiver = (? or ?) order by sent_date;
    <sql:param value="${fn:trim(param.cust)}"/>
    <sql:param value="${fn:trim(param.servp)}"/>
</sql:query>

<sql:query var="getServp">
    select distinct sender from messages where receiver = ?;
    <sql:param value="${fn:trim(param.cust)}"/>    
</sql:query>


<!DOCTYPE html>
<html>
    <jsp:include page="head.jsp"/>

    <body>
        <jsp:include page="header.jsp"/>

        <div class="row">
            <div class="container">
                <div class="content row">

                    <div class="containerService">

                        <div class="panel panel-primary">
                            <div class="panel-heading">
                                <h3 class="panel-title">MESSAGE CONVERSATION</h3>
                            </div>

                            <div class="panel-body">
                                <table class="table table-hover table-condensed">
                                    <thead>  
                                        <tr>  
                                            <th>SENDER</th>
                                            <th>MESSAGE</th> 
                                        </tr>  
                                    </thead> 
                                    <tbody>
                                        <c:forEach var="contracts" items="${getConversation.rows}">                                          
                                            <tr>                                       
                                                <td class="text-left">${contracts.sender}</td>                                   
                                                <td class="text-left">${contracts.msg}</td>
                                            </tr>  
                                        </c:forEach>
                                    </tbody>
                                </table>
                            </div><!-- END panel-body -->

                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                    <h3 class="panel-title">MESSAGE</h3>
                                </div>
                            </div>
                            <div class="panel-body">
                                <form action='sendMessage.jsp' method='post'>
                                    <c:forEach var="servp" items="${getServp.rows}">
                                        <input type="hidden" class="form-control1" name="receiver" value="${servp.sender}">
                                    </c:forEach>
                                        
                                    <label>Message:</label>
                                    <textarea class="form-control" name="message" rows="10" cols="50" ></textarea>
                                    <br>
                                    <button type="submit" class="btn btn-primary">SEND MESSAGE</button>
                                </form>

                            </div><!-- END panel-body -->

                        </div><!-- END panel-primary -->
                    </div><!-- END containerService -->

                </div><!-- END CONTENT CONTENT ROW -->
            </div><!-- END CONTAINER -->
        </div><!-- END ROW -->

        <jsp:include page="footer.jsp"/>

    </body>
</html>
